package com.cee.admin.modules.prod.battery.controller;

import com.cee.admin.common.BaseProdController;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.prod.battery.form.ProdProductBatteryFillDataVo;
import com.cee.ds.modules.prod.battery.service.IProdProductBatteryBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.cee.domain.constants.DomainConstants.COMMON_UNAUDITED_STATUS;
import static com.cee.domain.constants.DomainConstants.COMMON_UNSUBMITTED_AUDIT_STATUS;

/**
 * <p>
 * 电池产品数据填报基本信息 前端控制器
 * </p>
 *
 * @author lzj
 * @since 2024-10-17
 */
@Tag(name = "产品管理-产品-电池产品数据填报基本信息")
@RestController
@RequestMapping("/api/prod/product/battery/base")
public class ProdProductBatteryBaseController extends BaseProdController {

    @Autowired
    private IProdProductBatteryBaseService prodProductBatteryBaseService;

    @Operation(summary = "保存电池产品数据填报")
    @PostMapping("/save")
    public Result<Long> save(@RequestBody ProdProductBatteryFillDataVo form) {
        checkProductPermWithCity(form.getDataReport().getProductId());
        prodProductBatteryBaseService.saveOrSubmitWithAdmin(form, COMMON_UNSUBMITTED_AUDIT_STATUS);
        return success(form.getDataReport().getId());
    }

    @Operation(summary = "提交电池产品数据填报")
    @PostMapping("/submit")
    public Result<Boolean> submit(@RequestBody ProdProductBatteryFillDataVo prodFillVo) {
        checkProductPermWithCity(prodFillVo.getDataReport().getProductId());
        prodProductBatteryBaseService.compute(prodFillVo);
        return success(prodProductBatteryBaseService.saveOrSubmitWithAdmin(prodFillVo, COMMON_UNAUDITED_STATUS));
    }

    @Operation(summary = "查看电池产品数据填报详情")
    @GetMapping("/get/{id}")
    public Result<ProdProductBatteryFillDataVo> get(@PathVariable("id") @Parameter(description = "数据填报id") Long id) {
        checkReportPermWithCity(id);
        return success(prodProductBatteryBaseService.getFillDataByIdWithAdmin(id));
    }

    @Operation(summary = "删除电池产品数据填报")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") @Parameter(description = "数据填报id") Long id) {
        checkReportPermWithCity(id);
        return success(prodProductBatteryBaseService.removeFillDataByIdWithAdmin(id));
    }
}
